/*
 * SettingsPanel.java
 *
 * Created on March 2, 2005, 10:52 AM
 */
package com.bff.slimserver.musicjukebox.ui.settings;

import com.bff.bjj.lib.actions.BugTrackerAction;
import com.bff.bjj.lib.actions.DiscussAction;
import com.bff.bjj.lib.actions.HomeAction;
import com.bff.bjj.lib.actions.WikiAction;
import com.bff.bjj.ui.GroupByFolderCheckBox;
import com.bff.bjj.ui.LAFPanel;
import com.bff.bjj.ui.component.BJJButton;
import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.slimserver.musicjukebox.lib.StartSqueeze;
import com.bff.slimserver.musicjukebox.lib.actions.SlimHomeAction;
import com.bff.slimserver.musicjukebox.ui.AboutDialog;
import com.bff.slimserver.musicjukebox.ui.ErrorDialog;
import com.bff.slimserver.musicjukebox.ui.SplashScreen;
import com.bff.bjj.ui.component.BJJPanel;
import com.bff.slimserver.musicjukebox.ui.database.SlimUpdateDialog;
import com.bff.bjj.utils.BrowserLauncher;
import com.bff.bjj.utils.Resources;
import com.bff.bjj.utils.Resources.LABEL_KEY;
import com.bff.bjj.utils.Utils;
import com.bff.slimserver.musicjukebox.ui.PreferencesPanel;
import com.bff.slimserver.musicjukebox.ui.StatPanel;
import com.bff.slimserver.musicjukebox.ui.database.DatabaseProgressPanel;
import com.bff.startup.StartApp;
import com.bff.startup.StartUpProperties;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import org.bff.slimserver.SlimServer;
import org.bff.slimserver.events.DatabaseScanEvent;
import org.bff.slimserver.events.DatabaseScanListener;
import org.bff.slimserver.exception.SlimConnectionException;

/**
 *
 * @author  bill
 */
public class SettingsPanel extends BJJPanel implements
        DatabaseScanListener {

    private JukeboxProperties jp;
    private boolean firstTime = false;
    private boolean connectionSuccessful = false;
    private JPanel panel;
    private SplashScreen sp;
    private DefaultComboBoxModel clientModel;
    private DefaultComboBoxModel explorerModel;
    private DefaultComboBoxModel coverArtSizeModel;
    private DefaultComboBoxModel exitModel;
    private boolean restartRequired;
    private Action homeAction;
    private static final String CLIENT_TOP = Resources.getMessage(LABEL_KEY.SETTINGS_PLAYLIST_TAB);
    private static final String CLIENT_LEFT = Resources.getMessage(LABEL_KEY.SETTINGS_PLAYLIST_LEFT);
    private static final String EXPLORER_LIST = Resources.getMessage(LABEL_KEY.SETTINGS_EXPLORER_LIST);
    private static final String EXPLORER_TREE = Resources.getMessage(LABEL_KEY.SETTINGS_EXPLORER_TREE);
    private static final String EXIT_STOP = Resources.getMessage(LABEL_KEY.SETTINGS_EXIT_STOP);
    private static final String EXIT_NOTHING = Resources.getMessage(LABEL_KEY.SETTINGS_EXIT_NOTHING);
    private DatabaseProgressPanel progressPanel;

    public SettingsPanel() {
        this(false);
    }

    /** Creates new form SettingsPanel */
    public SettingsPanel(boolean firstTime) {
        super();

        this.firstTime = firstTime;

        homeAction = new SlimHomeAction();

        clientModel = new DefaultComboBoxModel();
        clientModel.addElement(CLIENT_TOP);
        clientModel.addElement(CLIENT_LEFT);

        explorerModel = new DefaultComboBoxModel();
        explorerModel.addElement(EXPLORER_LIST);
        explorerModel.addElement(EXPLORER_TREE);

        coverArtSizeModel = new DefaultComboBoxModel();
        coverArtSizeModel.addElement(new Integer(50));
        coverArtSizeModel.addElement(new Integer(100));
        coverArtSizeModel.addElement(new Integer(150));
        coverArtSizeModel.addElement(new Integer(200));
        coverArtSizeModel.addElement(new Integer(250));
        coverArtSizeModel.addElement(new Integer(300));

        exitModel = new DefaultComboBoxModel();
        exitModel.addElement(EXIT_NOTHING);
        exitModel.addElement(EXIT_STOP);

        jp = JukeboxProperties.getInstance();

        initComponents();

        if (!firstTime) {
            //fill in the fields
            setSlimServer(jp.getServer());
            setPortCLI(Integer.toString(jp.getPort()));
            setPortWeb(Integer.toString(jp.getWebPort()));
            setPassword(jp.getUser(), jp.getPassword());
            setCoverArt(jp.isShowCoverArt());
            btnRefresh.setVisible(!firstTime);
            setClientType(jp.getClientType());
            setCoverArtSize(jp.getCoverSize());
            setMinTray(jp.isTrayMin());
            setImageDelay(jp.getImageDelay());
            setExplorerType(jp.isUseTreeExplorer() ? EXPLORER_TREE : EXPLORER_LIST);
            setExitAction(jp.isStopOnExit() ? EXIT_STOP : EXIT_NOTHING);
            setRememberState(StartUpProperties.getInstance().isUseLastState());
            setShowGuitar(jp.isShowGuitarPanel());
            setShowAlbums(jp.isShowAlbumsPanel());
            setShowPodcast(jp.isShowPodcastPanel());
            setShowRadios(jp.isShowRadiosPanel());
            setShowServices(jp.isShowServicesPanel());
            setShowFavorites(jp.isShowFavoritesPanel());
            setShowNewMusic(jp.isShowNewMusicPanel());
            setCheckForUpdate(jp.isCheckForUpdate());
            setIncludeThe(jp.isIncludeThe());
            setTrayAlways(jp.isTrayAlways());
            setGroupByFolder(jp.isGroupByFolder());
            if (!jp.isTrayAlways() && !jp.isTrayMin()) {
                setTrayNever(true);
            }

            statisticsPanel.add(new StatPanel());
            statisticsPanel.add(new PreferencesPanel());

            jp.getSlimMonitor().addDatabaseScanListener(this);
            createProgressPanel();

            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        if (jp.isDeveloper()) {
                            lblUpdate.setVisible(true);
                            lblUpdate.setText(getResource(LABEL_KEY.SETTINGS_DEVELOPER));
                            btnGetUpdate.setVisible(true);
                        } else if (jp.isSnapShot()) {
                            lblUpdate.setVisible(true);
                            lblUpdate.setText(getResource(LABEL_KEY.SETTINGS_SNAPSHOT));
                            btnGetUpdate.setVisible(true);
                        } else if (!jp.getVersion().equalsIgnoreCase(jp.versionAvailable())) {
                            lblUpdate.setVisible(true);
                            lblUpdate.setText(getResource(LABEL_KEY.SETTINGS_UPDATE));
                            btnGetUpdate.setVisible(true);
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(SettingsPanel.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }).start();

        } else {
            setCoverArtSize(200);
            setTrayNever(true);
            mainTabbedPane.remove(statisticsPanel);
            mainTabbedPane.remove(dbPanel);
        }

        panel = this;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        trayButtonGroup = new javax.swing.ButtonGroup();
        settingsPanel = new BJJPanel();
        buttonPanel = new BJJPanel();
        saveButton = new com.bff.bjj.ui.component.BJJButton();
        btnAbout = new com.bff.bjj.ui.component.BJJButton();
        btnHome = new com.bff.bjj.ui.component.BJJButton(homeAction);
        btnHome.setIcon(null);
        lblUpdate = new javax.swing.JLabel();
        lblUpdate.setVisible(false);
        btnGetUpdate = new com.bff.bjj.ui.component.BJJButton();
        btnGetUpdate.setVisible(false);
        mainTabbedPane = new javax.swing.JTabbedPane();
        scSettings = new BJJPanel();
        portPanel = new BJJPanel();
        jLabel6 = new javax.swing.JLabel();
        tfSlimCLIPort = new javax.swing.JTextField();
        tfSlimWebPort = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        tfSlimAddress = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        discoverButton = new BJJButton();
        passwordPanel = new BJJPanel();
        cbPassword = new javax.swing.JCheckBox();
        jLabel10 = new javax.swing.JLabel();
        tfUserName = new javax.swing.JTextField();
        tfPassword = new javax.swing.JPasswordField();
        jLabel8 = new javax.swing.JLabel();
        jPanel2 = new BJJPanel();
        btnBugReport = new com.bff.bjj.ui.component.BJJButton();
        btnHomePage = new com.bff.bjj.ui.component.BJJButton();
        btnWiki = new com.bff.bjj.ui.component.BJJButton();
        btnDiscuss = new com.bff.bjj.ui.component.BJJButton();
        miscPanel = new BJJPanel();
        jPanel3 = new BJJPanel();
        chkboxCheckForUpdate = new javax.swing.JCheckBox();
        chkboxLastState = new javax.swing.JCheckBox();
        chkboxIncludeThe = new javax.swing.JCheckBox();
        chkboxGroupByFolder = new GroupByFolderCheckBox();
        typePanel = new BJJPanel();
        jLabel12 = new javax.swing.JLabel();
        cbClientType = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        cbExplorerType = new javax.swing.JComboBox();
        exitPanel = new BJJPanel();
        jLabel16 = new javax.swing.JLabel();
        cbExitAction = new javax.swing.JComboBox();
        jPanel1 = new BJJPanel();
        chkboxPodcast = new javax.swing.JCheckBox();
        chkboxServices = new javax.swing.JCheckBox();
        chkboxAlbums = new javax.swing.JCheckBox();
        chkboxRadios = new javax.swing.JCheckBox();
        chkboxGuitar = new javax.swing.JCheckBox();
        chkboxFavorites = new javax.swing.JCheckBox();
        chkboxNewMusic = new javax.swing.JCheckBox();
        lafPanel = new LAFPanel();
        jPanel4 = new BJJPanel();
        chkboxMinTray = new javax.swing.JCheckBox();
        chkboxTrayAlways = new javax.swing.JCheckBox();
        chkboxTrayNever = new javax.swing.JCheckBox();
        coverArtSettings = new BJJPanel();
        cbCoverArt = new javax.swing.JCheckBox();
        jLabel14 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        cbCoverArtSize = new javax.swing.JComboBox();
        tfImageDelay = new javax.swing.JTextField();
        dbPanel = new BJJPanel();
        jPanel5 = new BJJPanel();
        jPanel7 = new BJJPanel();
        btnRefresh = new com.bff.bjj.ui.component.BJJButton();
        btnClearAndScan = new com.bff.bjj.ui.component.BJJButton();
        jPanel6 = new BJJPanel();
        btnScanDone = new com.bff.bjj.ui.component.BJJButton();
        statisticsPanel = new BJJPanel();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));

        settingsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("SqueezeCenter Settings"));
        settingsPanel.setLayout(new java.awt.GridBagLayout());

        buttonPanel.setLayout(new java.awt.GridBagLayout());

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("messages"); // NOI18N
        saveButton.setText(bundle.getString("SETTINGS_BUTTON_SAVE")); // NOI18N
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        buttonPanel.add(saveButton, gridBagConstraints);

        btnAbout.setText(bundle.getString("SETTINGS_BUTTON_ABOUT")); // NOI18N
        btnAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAboutActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        buttonPanel.add(btnAbout, gridBagConstraints);

        btnHome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHomeActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        buttonPanel.add(btnHome, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        settingsPanel.add(buttonPanel, gridBagConstraints);

        lblUpdate.setForeground(java.awt.Color.red);
        lblUpdate.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblUpdate.setText("An update is availble.");
        lblUpdate.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        settingsPanel.add(lblUpdate, gridBagConstraints);

        btnGetUpdate.setText("Get Update");
        btnGetUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGetUpdateActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
        settingsPanel.add(btnGetUpdate, gridBagConstraints);

        scSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        scSettings.setLayout(new java.awt.GridBagLayout());

        portPanel.setLayout(new java.awt.GridBagLayout());

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel6.setText(bundle.getString("SETTINGS_LABEL_CLIPORT")); // NOI18N
        jLabel6.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        portPanel.add(jLabel6, gridBagConstraints);

        tfSlimCLIPort.setText("9090");
        tfSlimCLIPort.setPreferredSize(new java.awt.Dimension(50, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        portPanel.add(tfSlimCLIPort, gridBagConstraints);

        tfSlimWebPort.setText("9000");
        tfSlimWebPort.setPreferredSize(new java.awt.Dimension(50, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        portPanel.add(tfSlimWebPort, gridBagConstraints);

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel9.setText(bundle.getString("SETTINGS_LABEL_WEBPORT")); // NOI18N
        jLabel9.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        portPanel.add(jLabel9, gridBagConstraints);

        tfSlimAddress.setColumns(15);
        tfSlimAddress.setPreferredSize(new java.awt.Dimension(150, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        portPanel.add(tfSlimAddress, gridBagConstraints);

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel7.setText(bundle.getString("SETTINGS_LABEL_ADDRESS")); // NOI18N
        jLabel7.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        portPanel.add(jLabel7, gridBagConstraints);

        discoverButton.setText("Find");
        discoverButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                discoverButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        portPanel.add(discoverButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        scSettings.add(portPanel, gridBagConstraints);

        passwordPanel.setLayout(new java.awt.GridBagLayout());

        cbPassword.setText(bundle.getString("SETTINGS_LABEL_USE_PASSWORD")); // NOI18N
        cbPassword.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        cbPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbPasswordActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        passwordPanel.add(cbPassword, gridBagConstraints);

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel10.setText(bundle.getString("SETTINGS_LABEL_USER_NAME")); // NOI18N
        jLabel10.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        jLabel10.setEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        passwordPanel.add(jLabel10, gridBagConstraints);

        tfUserName.setEnabled(false);
        tfUserName.setPreferredSize(new java.awt.Dimension(150, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        passwordPanel.add(tfUserName, gridBagConstraints);

        tfPassword.setEnabled(false);
        tfPassword.setPreferredSize(new java.awt.Dimension(150, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        passwordPanel.add(tfPassword, gridBagConstraints);

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel8.setText(bundle.getString("SETTINGS_LABEL_USE_PASSWORD")); // NOI18N
        jLabel8.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        jLabel8.setEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        passwordPanel.add(jLabel8, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        scSettings.add(passwordPanel, gridBagConstraints);

        btnBugReport.setAction(new BugTrackerAction());
        jPanel2.add(btnBugReport);

        btnHomePage.setAction(new HomeAction());
        jPanel2.add(btnHomePage);

        btnWiki.setAction(new WikiAction());
        jPanel2.add(btnWiki);

        btnDiscuss.setAction(new DiscussAction());
        jPanel2.add(btnDiscuss);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        scSettings.add(jPanel2, gridBagConstraints);

        mainTabbedPane.addTab(bundle.getString("SETTINGS_TAB_SERVER"), scSettings); // NOI18N

        miscPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        miscPanel.setLayout(new java.awt.GridBagLayout());

        jPanel3.setLayout(new java.awt.GridBagLayout());

        chkboxCheckForUpdate.setSelected(true);
        chkboxCheckForUpdate.setText("Check for update at startup");
        jPanel3.add(chkboxCheckForUpdate, new java.awt.GridBagConstraints());

        chkboxLastState.setText("Remember last state");
        jPanel3.add(chkboxLastState, new java.awt.GridBagConstraints());

        chkboxIncludeThe.setText("Include 'The' in sort");
        jPanel3.add(chkboxIncludeThe, new java.awt.GridBagConstraints());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        jPanel3.add(chkboxGroupByFolder, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        miscPanel.add(jPanel3, gridBagConstraints);

        typePanel.setLayout(new java.awt.GridBagLayout());

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel12.setText("Client Type:");
        jLabel12.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        typePanel.add(jLabel12, gridBagConstraints);

        cbClientType.setModel(clientModel);
        cbClientType.setMinimumSize(new java.awt.Dimension(100, 27));
        cbClientType.setPreferredSize(new java.awt.Dimension(125, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        typePanel.add(cbClientType, gridBagConstraints);

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel15.setText("Explorer Type:");
        jLabel15.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        typePanel.add(jLabel15, gridBagConstraints);

        cbExplorerType.setModel(explorerModel);
        cbExplorerType.setPreferredSize(new java.awt.Dimension(125, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        typePanel.add(cbExplorerType, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        miscPanel.add(typePanel, gridBagConstraints);

        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel16.setText("Exit Action:");
        jLabel16.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        exitPanel.add(jLabel16);

        cbExitAction.setModel(exitModel);
        cbExitAction.setPreferredSize(new java.awt.Dimension(125, 25));
        exitPanel.add(cbExitAction);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        miscPanel.add(exitPanel, gridBagConstraints);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Panels"));
        jPanel1.setLayout(new java.awt.GridBagLayout());

        chkboxPodcast.setSelected(true);
        chkboxPodcast.setText("Show Podcast Panel");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel1.add(chkboxPodcast, gridBagConstraints);

        chkboxServices.setSelected(true);
        chkboxServices.setText("Show Services Panel");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel1.add(chkboxServices, gridBagConstraints);

        chkboxAlbums.setSelected(true);
        chkboxAlbums.setText("Show Albums Panel");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel1.add(chkboxAlbums, gridBagConstraints);

        chkboxRadios.setSelected(true);
        chkboxRadios.setText("Show Radios Panel");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel1.add(chkboxRadios, gridBagConstraints);

        chkboxGuitar.setText("Show Guitar Panel");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel1.add(chkboxGuitar, gridBagConstraints);

        chkboxFavorites.setSelected(true);
        chkboxFavorites.setText("Show Favorites Panel");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel1.add(chkboxFavorites, gridBagConstraints);

        chkboxNewMusic.setSelected(true);
        chkboxNewMusic.setText(getResource(LABEL_KEY.SETTINGS_SHOW_NEW_MUSIC));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel1.add(chkboxNewMusic, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        miscPanel.add(jPanel1, gridBagConstraints);

        lafPanel.setOpaque(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        miscPanel.add(lafPanel, gridBagConstraints);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Tray Support"));
        jPanel4.setLayout(new java.awt.GridBagLayout());

        trayButtonGroup.add(chkboxMinTray);
        chkboxMinTray.setText("Minimize to tray");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel4.add(chkboxMinTray, gridBagConstraints);

        trayButtonGroup.add(chkboxTrayAlways);
        chkboxTrayAlways.setText("Always in tray");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel4.add(chkboxTrayAlways, gridBagConstraints);

        trayButtonGroup.add(chkboxTrayNever);
        chkboxTrayNever.setText("Never in Tray");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel4.add(chkboxTrayNever, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        miscPanel.add(jPanel4, gridBagConstraints);

        coverArtSettings.setBorder(javax.swing.BorderFactory.createTitledBorder("Cover Art"));
        coverArtSettings.setLayout(new java.awt.GridBagLayout());

        cbCoverArt.setSelected(true);
        cbCoverArt.setText(bundle.getString("SETTINGS_LABEL_SHOW_COVER_ART")); // NOI18N
        cbCoverArt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbCoverArtActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        coverArtSettings.add(cbCoverArt, gridBagConstraints);

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel14.setText("Fade Delay Seconds (0 for none):");
        jLabel14.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        coverArtSettings.add(jLabel14, gridBagConstraints);

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel13.setText("Cover Art Size:");
        jLabel13.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        coverArtSettings.add(jLabel13, gridBagConstraints);

        cbCoverArtSize.setModel(coverArtSizeModel);
        cbCoverArtSize.setPreferredSize(new java.awt.Dimension(100, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        coverArtSettings.add(cbCoverArtSize, gridBagConstraints);

        tfImageDelay.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        tfImageDelay.setText(Integer.toString(JukeboxProperties.DEFAULT_IMAGE_DELAY));
        tfImageDelay.setMinimumSize(new java.awt.Dimension(30, 20));
        tfImageDelay.setPreferredSize(new java.awt.Dimension(30, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        coverArtSettings.add(tfImageDelay, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        miscPanel.add(coverArtSettings, gridBagConstraints);

        mainTabbedPane.addTab(bundle.getString("SETTINGS_TAB_MISC"), miscPanel); // NOI18N

        dbPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        dbPanel.setLayout(new java.awt.BorderLayout());
        dbPanel.add(jPanel5, java.awt.BorderLayout.CENTER);

        btnRefresh.setText(bundle.getString("SETTINGS_BUTTON_REFRESH")); // NOI18N
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });
        jPanel7.add(btnRefresh);

        btnClearAndScan.setText(bundle.getString("SETTINGS_BUTTON_CLEAR_SCAN")); // NOI18N
        btnClearAndScan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnClearAndScanActionPerformed(evt);
            }
        });
        jPanel7.add(btnClearAndScan);

        dbPanel.add(jPanel7, java.awt.BorderLayout.NORTH);

        btnScanDone.setText("Done");
        btnScanDone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnScanDoneActionPerformed(evt);
            }
        });
        jPanel6.add(btnScanDone);

        dbPanel.add(jPanel6, java.awt.BorderLayout.SOUTH);

        mainTabbedPane.addTab(bundle.getString("SETTINGS_TAB_DB"), dbPanel); // NOI18N

        statisticsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        mainTabbedPane.addTab(bundle.getString("SETTINGS_TAB_STAT"), statisticsPanel); // NOI18N

        settingsPanel.add(mainTabbedPane, new java.awt.GridBagConstraints());

        add(settingsPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed
        new AboutDialog(Utils.getParentComponent(this)).setVisible(true);
    }//GEN-LAST:event_btnAboutActionPerformed

    private void cbPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPasswordActionPerformed
        if (cbPassword.isSelected()) {
            setPasswordFields(true);
        } else {
            setPasswordFields(false);
        }
    }//GEN-LAST:event_cbPasswordActionPerformed

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        try {
            new SlimUpdateDialog(Utils.getParentComponent(this), false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        try {
            setCursor(Utils.getHourglassCursor());

            String slimServer = getSlimServer();
            String slimPort = getPortCLI();
            String slimWebPort = getPortWeb();
            String userName = getUserName();
            String password = getPassword();

            String msg = "";

            if (slimServer.length() < 1 || slimPort.length() < 1 || slimWebPort.length() < 1) {
                msg = "Must Enter Slim Server Information!\n";
            }

            if (cbPassword.isSelected() && password.length() < 1) {
                msg += "Must enter a password!";
            }

            if (cbPassword.isSelected() && userName.length() < 1) {
                msg += "Must enter a user name!";
            }

            if (!msg.equals("")) {
                JOptionPane.showMessageDialog(this, msg);
            } else {
                if (!saveSettings()) {
                    JOptionPane.showMessageDialog(this, "Problem Writing File! Please Verify Information.");
                } else {
                    settingsSaved();
                }
            }
        } finally {
            setCursor(Utils.getNormalCursor());
        }
    }//GEN-LAST:event_saveButtonActionPerformed

private void btnClearAndScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearAndScanActionPerformed

    try {
        int n = JOptionPane.showConfirmDialog(this,
                "Are you sure you want to clear and rescan?",
                "Clear and Rescan",
                JOptionPane.YES_NO_OPTION);

        if (n == JOptionPane.YES_OPTION) {
            new SlimUpdateDialog(Utils.getParentComponent(this), true);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}//GEN-LAST:event_btnClearAndScanActionPerformed

private void btnGetUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGetUpdateActionPerformed
    BrowserLauncher.openURL(jp.getUpdateURL());
}//GEN-LAST:event_btnGetUpdateActionPerformed

private void cbCoverArtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCoverArtActionPerformed
    if (cbCoverArt.isSelected()) {
        setImageDelayFields(true);
    } else {
        setImageDelayFields(false);
    }
}//GEN-LAST:event_cbCoverArtActionPerformed

private void btnHomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHomeActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btnHomeActionPerformed

private void discoverButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_discoverButtonActionPerformed
    DiscoveryDialog dd = new DiscoveryDialog(Utils.getParentComponent(this), true);
    dd.setSize(new Dimension(600, 225));
    Utils.centerInParent(dd, Utils.getParentComponent(this));
    dd.startSearch();
    dd.setVisible(true);

    if (dd.getSelectedServer() != null) {
        tfSlimAddress.setText(dd.getSelectedServer().getHostAddress());
    }

    dd.stopSearch();
}//GEN-LAST:event_discoverButtonActionPerformed

    private void btnScanDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnScanDoneActionPerformed
        progressPanel.setVisible(false);
        btnScanDone.setVisible(false);
        jPanel7.setVisible(true);
		}//GEN-LAST:event_btnScanDoneActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAbout;
    private javax.swing.JButton btnBugReport;
    private javax.swing.JButton btnClearAndScan;
    private javax.swing.JButton btnDiscuss;
    private javax.swing.JButton btnGetUpdate;
    private javax.swing.JButton btnHome;
    private javax.swing.JButton btnHomePage;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnScanDone;
    private javax.swing.JButton btnWiki;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JComboBox cbClientType;
    private javax.swing.JCheckBox cbCoverArt;
    private javax.swing.JComboBox cbCoverArtSize;
    private javax.swing.JComboBox cbExitAction;
    private javax.swing.JComboBox cbExplorerType;
    private javax.swing.JCheckBox cbPassword;
    private javax.swing.JCheckBox chkboxAlbums;
    private javax.swing.JCheckBox chkboxCheckForUpdate;
    private javax.swing.JCheckBox chkboxFavorites;
    private javax.swing.JCheckBox chkboxGroupByFolder;
    private javax.swing.JCheckBox chkboxGuitar;
    private javax.swing.JCheckBox chkboxIncludeThe;
    private javax.swing.JCheckBox chkboxLastState;
    private javax.swing.JCheckBox chkboxMinTray;
    private javax.swing.JCheckBox chkboxNewMusic;
    private javax.swing.JCheckBox chkboxPodcast;
    private javax.swing.JCheckBox chkboxRadios;
    private javax.swing.JCheckBox chkboxServices;
    private javax.swing.JCheckBox chkboxTrayAlways;
    private javax.swing.JCheckBox chkboxTrayNever;
    private javax.swing.JPanel coverArtSettings;
    private javax.swing.JPanel dbPanel;
    private javax.swing.JButton discoverButton;
    private javax.swing.JPanel exitPanel;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel lafPanel;
    private javax.swing.JLabel lblUpdate;
    private javax.swing.JTabbedPane mainTabbedPane;
    private javax.swing.JPanel miscPanel;
    private javax.swing.JPanel passwordPanel;
    private javax.swing.JPanel portPanel;
    private javax.swing.JButton saveButton;
    private javax.swing.JPanel scSettings;
    private javax.swing.JPanel settingsPanel;
    private javax.swing.JPanel statisticsPanel;
    private javax.swing.JTextField tfImageDelay;
    private javax.swing.JPasswordField tfPassword;
    private javax.swing.JTextField tfSlimAddress;
    private javax.swing.JTextField tfSlimCLIPort;
    private javax.swing.JTextField tfSlimWebPort;
    private javax.swing.JTextField tfUserName;
    private javax.swing.ButtonGroup trayButtonGroup;
    private javax.swing.JPanel typePanel;
    // End of variables declaration//GEN-END:variables

    private void setSlimServer(String server) {
        tfSlimAddress.setText(server);
    }

    private String getSlimServer() {
        return (tfSlimAddress.getText().trim());
    }

    private void setPortCLI(String port) {
        tfSlimCLIPort.setText(port);
    }

    private String getPortCLI() {
        return (tfSlimCLIPort.getText().trim());
    }

    private void setPortWeb(String port) {
        tfSlimWebPort.setText(port);
    }

    private String getPortWeb() {
        return (tfSlimWebPort.getText().trim());
    }

    private boolean saveSettings() {

        try {
            if (!jp.getServer().equalsIgnoreCase(getSlimServer().trim())
                    || jp.getPort() != Integer.parseInt(getPortCLI().trim())
                    || jp.getWebPort() != Integer.parseInt(getPortWeb().trim())
                    || jp.getClientType() != getClientType()) {
                setRestartRequired(true);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        jp.setServer(getSlimServer());
        jp.setPort(Integer.parseInt(getPortCLI()));
        jp.setWebPort(Integer.parseInt(getPortWeb()));
        jp.setShowCoverArt(getShowCoverArt());
        jp.setTrayMin(getMinTray());
        jp.setTrayAlways(getTrayAlways());
        if (cbPassword.isSelected()) {
            jp.setUser(getUserName());
            jp.setPassword(getPassword());
        } else {
            jp.setUser(null);
            jp.setPassword(null);
        }
        jp.setImageDelay(getImageDelay() > JukeboxProperties.MAX_IMAGE_DELAY
                ? JukeboxProperties.DEFAULT_IMAGE_DELAY
                : getImageDelay());

        jp.setClientType(getClientType());
        jp.setUseTreeExplorer(getExplorerType().equalsIgnoreCase(EXPLORER_TREE));
        jp.setStopOnExit(getExitAction().equalsIgnoreCase(EXIT_STOP));
        jp.setCoverSize(getCoverArtSize());
        jp.setShowGuitarPanel(getShowGuitar());
        jp.setShowAlbumsPanel(getShowAlbums());
        jp.setShowPodcastPanel(getShowPodcast());
        jp.setShowFavoritesPanel(getShowFavorites());
        jp.setShowNewMusicPanel(getShowNewMusic());
        jp.setShowRadiosPanel(getShowRadios());
        jp.setShowServicesPanel(getShowServices());
        jp.setCheckForUpdate(getCheckForUpdate());
        jp.setIncludeThe(getIncludeThe());
        jp.setGroupByFolder(getGroupByFolder());
        StartUpProperties.getInstance().saveSettings(getRememberState());

        return (jp.saveSettings());
    }

    private void setCoverArtSize(int coverSize) {
        cbCoverArtSize.setSelectedItem(coverSize);
    }

    private int getCoverArtSize() {
        return (Integer) cbCoverArtSize.getSelectedItem();
    }

    private void settingsSaved() {
        if (!isFirstTime()) {

            if (isRestartRequired()) {
                int ch = JOptionPane.showConfirmDialog(this,
                        getResource(LABEL_KEY.SETTINGS_MESSAGE_RESTART),
                        getResource(LABEL_KEY.SETTINGS_MESSAGE_RESTART_TITLE),
                        JOptionPane.YES_NO_OPTION);
                if (ch == JOptionPane.YES_OPTION) {
                    if (!StartApp.restartApp()) {
                        JOptionPane.showMessageDialog(this,
                                getResource(LABEL_KEY.SETTINGS_MESSAGE_RESTART_ERROR),
                                getResource(LABEL_KEY.SETTINGS_MESSAGE_RESTART_ERROR_TITLE),
                                JOptionPane.ERROR_MESSAGE);
                    }
                }
            } else {
                JOptionPane.showMessageDialog(this, getResource(LABEL_KEY.SETTINGS_MESSAGE_SAVED_SUCCESS));
            }
        } else {
            sp = new SplashScreen(true);
            sp.setIndeterminate(true);
            sp.setTitleLabel(getResource(LABEL_KEY.SETTINGS_MESSAGE_CONNECTION_TEST_TITLE));
            sp.setMainTextArea(getResource(LABEL_KEY.SETTINGS_MESSAGE_CONNECTION_TEST));
            sp.setProgressBarLabel(getResource(LABEL_KEY.SETTINGS_MESSAGE_CONNECTION_TEST_PROGRESS));

            Thread t = new Thread(new SlimTester());
            t.start();
        }
    }

    private boolean isFirstTime() {
        return firstTime;
    }

    private void setFirstTime(boolean firstTime) {
        if (firstTime) {
            buttonPanel.setLayout(new FlowLayout());
            btnRefresh.setVisible(false);
            btnClearAndScan.setVisible(false);
            btnAbout.setVisible(false);
        }
        this.firstTime = firstTime;
    }

    /**
     * @return the restartRequired
     */
    private boolean isRestartRequired() {
        return restartRequired;
    }

    /**
     * @param restartRequired the restartRequired to set
     */
    private void setRestartRequired(boolean restartRequired) {
        this.restartRequired = restartRequired;
    }

    private void createProgressPanel() {
        try {
            progressPanel = new DatabaseProgressPanel();
            jPanel5.add(progressPanel);

            if (jp.getDatabase().isRescanning()) {
                progressPanel.setVisible(true);
            } else {
                progressPanel.setVisible(false);
            }

            btnScanDone.setVisible(false);
        } catch (SlimConnectionException ex) {
            Logger.getLogger(SettingsPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void databaseScanEventReceived(DatabaseScanEvent event) {
        switch (event.getId()) {
            case DatabaseScanEvent.SCAN_STARTED:
                progressPanel.setVisible(true);
                jPanel5.setVisible(true);
                break;
            case DatabaseScanEvent.SCAN_ENDED:
                progressPanel.setDone();
                btnScanDone.setVisible(true);
                break;
        }
    }

    private class SlimTester implements Runnable {

        @Override
        public void run() {
            try {
                SlimServer ss = jp.getSlimServer();
                ss.isConnected();
                setConnectionSuccessful(true);
            } catch (Exception e) {
                e.printStackTrace();
                setConnectionSuccessful(false);
                new ErrorDialog((JFrame) Utils.getParentComponent(panel),
                        getResource(LABEL_KEY.SETTINGS_MESSAGE_CONNECTION_TEST_ERROR),
                        e.getMessage(),
                        false);
            } finally {
                sp.setStopped(true);
            }

            if (isConnectionSuccessful()) {
                jp.resetProperties();
                Utils.getParentComponent(panel).dispose();
                StartSqueeze.runApp();
            } else {
                setVisible(true);
            }
        }
    }

    private boolean isConnectionSuccessful() {
        return connectionSuccessful;
    }

    private void setConnectionSuccessful(boolean connectionSuccessful) {
        this.connectionSuccessful = connectionSuccessful;
    }

    private void setPasswordFields(boolean b) {
        jLabel8.setEnabled(b);
        tfPassword.setEnabled(b);
        jLabel10.setEnabled(b);
        tfUserName.setEnabled(b);
    }

    private void setImageDelayFields(boolean b) {
        jLabel14.setEnabled(b);
        tfImageDelay.setEnabled(b);
    }

    private String getUserName() {
        return tfUserName.getText().trim();
    }

    private String getPassword() {
        return new String(tfPassword.getPassword()).trim();
    }

    private void setPassword(String userName, String password) {
        if (password != null && password.length() > 0) {
            cbPassword.setSelected(true);
        }
        tfPassword.setText(password);
        tfUserName.setText(userName);
    }

    private boolean getShowCoverArt() {
        return cbCoverArt.isSelected();
    }

    private void setCoverArt(boolean showCoverArt) {
        cbCoverArt.setSelected(showCoverArt);
        setImageDelayFields(showCoverArt);
    }

    private boolean getShowGuitar() {
        return chkboxGuitar.isSelected();
    }

    private boolean getShowAlbums() {
        return chkboxAlbums.isSelected();
    }

    private boolean getShowPodcast() {
        return chkboxPodcast.isSelected();
    }

    private boolean getShowRadios() {
        return chkboxRadios.isSelected();
    }

    private boolean getShowFavorites() {
        return chkboxFavorites.isSelected();
    }

    private boolean getShowNewMusic() {
        return chkboxNewMusic.isSelected();
    }

    private boolean getShowServices() {
        return chkboxServices.isSelected();
    }

    private boolean getCheckForUpdate() {
        return chkboxCheckForUpdate.isSelected();
    }

    private boolean getIncludeThe() {
        return chkboxIncludeThe.isSelected();
    }

    private void setShowGuitar(boolean showGuitar) {
        chkboxGuitar.setSelected(showGuitar);
    }

    private void setShowAlbums(boolean showAlbums) {
        chkboxAlbums.setSelected(showAlbums);
    }

    private void setShowPodcast(boolean showPodcast) {
        chkboxPodcast.setSelected(showPodcast);
    }

    private void setShowFavorites(boolean showFavorites) {
        chkboxFavorites.setSelected(showFavorites);
    }

    private void setShowNewMusic(boolean showNewMusic) {
        chkboxNewMusic.setSelected(showNewMusic);
    }

    private void setCheckForUpdate(boolean checkForUpdate) {
        chkboxCheckForUpdate.setSelected(checkForUpdate);
    }

    private void setIncludeThe(boolean includeThe) {
        chkboxIncludeThe.setSelected(includeThe);
    }

    private void setShowRadios(boolean showRadios) {
        chkboxRadios.setSelected(showRadios);
    }

    private void setShowServices(boolean showServices) {
        chkboxServices.setSelected(showServices);
    }

    private boolean getRememberState() {
        return chkboxLastState.isSelected();
    }

    private void setRememberState(boolean rememberState) {
        chkboxLastState.setSelected(rememberState);
    }

    private boolean getMinTray() {
        return chkboxMinTray.isSelected();
    }

    private void setMinTray(boolean showCoverArt) {
        chkboxMinTray.setSelected(showCoverArt);
    }

    private boolean getTrayAlways() {
        return chkboxTrayAlways.isSelected();
    }

    private void setTrayAlways(boolean trayAlways) {
        chkboxTrayAlways.setSelected(trayAlways);
    }

    private void setTrayNever(boolean trayNever) {
        chkboxTrayNever.setSelected(trayNever);
    }

    private void setExplorerType(String explorerType) {
        cbExplorerType.setSelectedItem(explorerType);
    }

    private String getExplorerType() {
        return (String) cbExplorerType.getSelectedItem();
    }

    private void setExitAction(String exitAction) {
        cbExitAction.setSelectedItem(exitAction);
    }

    private String getExitAction() {
        return (String) cbExitAction.getSelectedItem();
    }

    private boolean getGroupByFolder() {
        return chkboxGroupByFolder.isSelected();
    }

    private void setGroupByFolder(boolean groupByFolder) {
        chkboxGroupByFolder.setSelected(groupByFolder);
    }

    private int getClientType() {
        String str = (String) cbClientType.getSelectedItem();
        if (str.equals(CLIENT_LEFT)) {
            return JukeboxProperties.CLIENT_PLAYER_LEFT;
        } else {
            return JukeboxProperties.CLIENT_PLAYER_TOP;
        }
    }

    private void setClientType(int clientType) {
        switch (clientType) {
            case JukeboxProperties.CLIENT_PLAYER_LEFT:
                cbClientType.setSelectedItem(CLIENT_LEFT);
                break;
            case JukeboxProperties.CLIENT_PLAYER_TOP:
                cbClientType.setSelectedItem(CLIENT_TOP);
                break;
            default:
                cbClientType.setSelectedItem(CLIENT_TOP);
                break;
        }
    }

    private void setImageDelay(int seconds) {
        tfImageDelay.setText(Integer.toString(seconds));
    }

    private int getImageDelay() {
        try {
            return Integer.parseInt(tfImageDelay.getText());
        } catch (Exception e) {
            return JukeboxProperties.DEFAULT_IMAGE_DELAY;
        }
    }

    public LAFPanel getLAFPanel() {
        return (LAFPanel) lafPanel;
    }
}
